
import app from "src/app";
var ObjectId = require('mongodb').ObjectId;

import configFile from './config';

import 'src/route/playerRoute'
import 'src/route/rankRoute'
import 'src/route/gameRoute'
import playerSessionHandle from "./handle/playerSessionHandle";



if (process.argv.length >= 3 && configFile[process.argv[3]]) {
    app.env = process.argv[3]
    app.config = configFile[process.argv[3]]
    app.gameName = configFile.gameName
} else {
    app.env = 'dev'
    app.config = configFile['dev']
    app.gameName = configFile.gameName
}
let forkID = Number(process.argv[2])
app.forkID = forkID
app.type = 'forkWorker'
playerSessionHandle.init()

// 监听退出事件
process.on('exit', () => {
    console.log('退出事件触发');
    // 执行退出前需要完成的任务，例如关闭数据库连接、文件流或定时器等
    playerSessionHandle.updatePlayer()
});

// 监听BeforeExit事件
process.on('beforeExit', (code) => {
    console.log('BeforeExit事件触发，退出码：', code);
    // 执行退出前需要完成的任务，例如日志记录或异步操作完成等
    playerSessionHandle.updatePlayer()
});
